<?php
ob_start();
include('config.php');

	require_once 'syslogin/usuario.php';
	require_once 'syslogin/autenticador.php';
	require_once 'syslogin/sessao.php';

	$aut = Autenticador::instanciar();
	$usuario = null;
	if ($aut->esta_logado()) {
		$usuario = $aut->pegar_usuario();
	}
	else {
		$aut->expulsar();
	}

if($_POST['postado']){
	$data = $_POST['data'];
	$query="SELECT A.data, E.nome AS nome_equip, horario, A.nome, comentario FROM reserva A LEFT JOIN horario H ON A.id_horario = H.id LEFT JOIN equipamento E ON E.id = A.id_equipamento 
	WHERE A.data = '$data' ORDER BY E.nome, H.horario";
	$ret=mysql_query($query,$conn) or die(mysql_error());
	$validacao = true;

}else{
	$validacao = false;
}



//$data_hoje = date("Y/m/d");
?>
			<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title">
						<span class="glyphicon glyphicon-search"></span> <strong>Consulta de Reservas</strong>
					</h3>
				</div>
				<div class="panel-body">
			<form class="form-horizontal" role="form" method="post" action="">
				<div class="form-group <?php echo $has_error; ?>">
					<label for="inputNome" class="col-sm-4 control-label">Data</label>
					<div class="col-sm-3">
						<input class="form-control" type="date" name="data" value="<?php echo $_POST['data'];?>" ></input>
					</div>
					<div class="col-sm-2">
						<input type="submit" class="btn btn-success" onClick="valida();" name="btn_consultar" value="Consultar">
					</div>
				</div>
				<input type="hidden" name="postado" value="1">
			</form>
				<?php 
					if($validacao){
					?>
						<table id="table" class="table table-hover table-condensed table-bordered">
							<thead>
								<tr class="success">
									<tr>
										<th>Data</th>
										<th>Sala ou Equipamento</th>
										<th>Horário</th>
										<th>Nome</th>
										<th>Comentários</th>
									</tr>
								</tr>
							</thead>
							<tbody>
						<?php while($res=mysql_fetch_assoc($ret)) { ?>
										<tr>
											<td align="center"><strong><?php echo date('d/m/Y', strtotime($res['data'])); ?></strong></td>
											<td><?php echo $res['nome_equip']; ?></td>
											<td><?php echo $res['horario']; ?></td>
											<td align="center"><?php echo $res['nome']; ?></td>
											<td><?php echo $res['comentario']; ?></td>
										</tr>
						<?php }; ?>
							</tbody>
						</table><?php
					}
				?>
				</div>
				<div class="panel-footer">
					<small><p class="text-right text-muted">Desenvolvido pela <a href="http://www.ifsertao-pe.edu.br/dgti" target="_blank" title="Coordenação de Tecnologia da Informação">CTI - Zona Rural</a></p></small>
				</div>
			</div>
		</div>
